package com.example.mountainwalker.mapper;

import com.example.mountainwalker.entity.StrategyLikeInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StrategyLikeMapper {
    @Select("SELECT sl.strategy_like_id as strategyLikeId, " +
            "sl.user_id as userId, " +
            "sl.strategy_id as strategyId, " +
            "sl.like_time as likeTime, " +
            "u.user_name as userName, " +
            "ts.strategy_name as strategyName " +
            "FROM strategy_like sl " +
            "LEFT JOIN user_info u ON sl.user_id = u.user_id " +
            "LEFT JOIN travel_strategy ts ON sl.strategy_id = ts.strategy_id")
    List<StrategyLikeInfo> getStrategyLikeInfo();

    @Select("SELECT sl.strategy_like_id as strategyLikeId, " +
            "sl.user_id as userId, " +
            "sl.strategy_id as strategyId, " +
            "sl.like_time as likeTime, " +
            "u.user_name as userName, " +
            "ts.strategy_name as strategyName " +
            "FROM strategy_like sl " +
            "LEFT JOIN user_info u ON sl.user_id = u.user_id " +
            "LEFT JOIN travel_strategy ts ON sl.strategy_id = ts.strategy_id " +
            "WHERE sl.strategy_like_id = #{id}")
    StrategyLikeInfo getStrategyLikeInfoById(Integer id);

    @Delete("DELETE FROM strategy_like WHERE strategy_like_id = #{id}")
    int deleteStrategyLikeInfoById(Integer id);

    @Insert("INSERT INTO strategy_like (user_id, strategy_id, like_time) " +
            "VALUES (#{userId}, #{strategyId}, #{likeTime})")
    @Options(useGeneratedKeys = true, keyProperty = "strategyLikeId")
    int insertStrategyLikeInfo(StrategyLikeInfo strategyLikeInfo);
}